package com.young.shop.service.impl;

import com.young.shop.dao.GoodsDao;
import com.young.shop.dao.impl.GoodsDaoimpl;
import com.young.shop.pojo.entity.Goods;
import com.young.shop.service.GoodsService;

import java.util.List;

public class GoodsServiceimpl implements GoodsService {

    private GoodsDao goodsDaoimpl = new GoodsDaoimpl();


    @Override
    public List<Goods> getAllGoods() {
        List<Goods> goodsList = goodsDaoimpl.servletGoodsAll();
        if (goodsList.size()==0){
            throw new RuntimeException("获取所有商品失败, 数据量为 0 ");
        }
        return goodsList;
    }

    @Override
    public List<Goods> queryGoodsByName(String name) {
        List<Goods> goodsList = goodsDaoimpl.servletGoodsByName(name);
        if (goodsList.size()==0){
            throw new RuntimeException("查询不到这个关键字的商品, 数据量为 0 ");
        }
        return goodsList;
    }

    @Override
    public Goods getGoodsById(String id) {
        Goods goods = goodsDaoimpl.getGoodsById(id);
        if (goods==null){
            throw new RuntimeException("没有这个商品");
        }
        return goods;
    }
}
